home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / bash / bash-110 / mintve~1 / bash110s.zoo / bash-1.10 / builtins / jobs.def < prev    next >
Encoding:
Text File  |  1991-08-04  |  2.7 KB  |  99 lines

  1. This file is jobs.def, from which is created jobs.c.
  2. It implements the builtin "jobs" in Bash.
  3.  
  4. Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc.
  5.  
  6. This file is part of GNU Bash, the Bourne Again SHell.
  7.  
  8. Bash is free software; you can redistribute it and/or modify it under
  9. the terms of the GNU General Public License as published by the Free
  10. Software Foundation; either version 1, or (at your option) any later
  11. version.
  12.  
  13. Bash is distributed in the hope that it will be useful, but WITHOUT ANY
  14. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  16. for more details.
  17.  
  18. You should have received a copy of the GNU General Public License along
  19. with Bash; see the file COPYING.  If not, write to the Free Software
  20. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22. $PRODUCES jobs.c
  23.  
  24. $BUILTIN jobs
  25. $FUNCTION jobs_builtin
  26. $DEPENDS_ON JOB_CONTROL
  27. $SHORT_DOC jobs [-lnp] [jobspec ...]
  28. Lists the active jobs.  The -l option lists process id's in addition
  29. to the normal information; the -p option lists process id's only.
  30. If -n is given, only processes that have changed status since the last
  31. notification are printed.  JOBSPEC restricts output to that job.
  32. $END
  33.  
  34. #include "../shell.h"
  35.  
  36. #if defined (JOB_CONTROL)
  37. #include <signal.h>
  38. #include <sys/types.h>
  39. #include "../jobs.h"
  40.  
  41. extern int job_control;
  42.  
  43. /* The `jobs' command.  Prints outs a list of active jobs.  If the
  44.    argument `-l' is given, then the process id's are printed also.
  45.    If the argument `-p' is given, print the process group leader's
  46.    pid only.  If `-n' is given, only processes that have changed
  47.    status since the last notification are printed. */
  48. int
  49. jobs_builtin (list)
  50.      WORD_LIST *list;
  51. {
  52.   int form = JLIST_STANDARD;
  53.  
  54.   if (!job_control)
  55.     return (EXECUTION_SUCCESS);
  56.  
  57.   while (list && (*list->word->word == '-'))
  58.     {
  59.       if (strcmp (list->word->word, "-l") == 0)
  60.     form = JLIST_LONG;
  61.       else if (strcmp (list->word->word, "-p") == 0)
  62.     form = JLIST_PID_ONLY;
  63.       else if (strcmp (list->word->word, "-n") == 0)
  64.     form = JLIST_CHANGED_ONLY;
  65.       else
  66.     {
  67.       bad_option (list->word->word);
  68.       return (EXECUTION_FAILURE);
  69.     }
  70.       list = list->next;
  71.     }
  72.  
  73.   if (!list)
  74.     {
  75.       list_jobs (form);
  76.       return (EXECUTION_SUCCESS);
  77.     }
  78.  
  79.   while (list)
  80.     {
  81.       int job;
  82.       sigset_t set, oset;
  83.  
  84.       BLOCK_CHILD (set, oset);
  85.       job = get_job_spec (list);
  86.  
  87.       if ((job == NO_JOB) || !jobs || !jobs[job])
  88.     builtin_error ("No such job %s", list->word->word);
  89.       else if (job != DUP_JOB)
  90.     list_one_job ((JOB *)NULL, form, 0, job);
  91.  
  92.       UNBLOCK_CHILD (oset);
  93.       list = list->next;
  94.     }
  95.     return (EXECUTION_SUCCESS);
  96. }
  97. #endif /* JOB_CONTROL */
  98.  
  99.